<template>
  <el-card class="userAvatar-container">
    <!-- 面板屑导航 -->
    <el-breadcrumb separator="/" style="margin-bottom: 40px">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>个人中心</el-breadcrumb-item>
      <el-breadcrumb-item>更换头像</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 用来展示头像的盒子 -->
    <div class="avatar-box">
      <img :src="userInfo.user_pic || imgURL" alt="" />
    </div>

    <!-- 按钮 -->
    <div class="btns">
      <!-- 文件选择框 -->
      <input type="file" accept="image/*" style="display: none" ref="fileRef" />
      <el-button type="primary" icon="el-icon-plus">选择图片</el-button>
      <el-button type="success" icon="el-icon-upload" :disabled="isDisabled"
        >上传头像
      </el-button>
    </div>
  </el-card>
</template>

<script>
// 导入默认图片
import img from '@/assets/images/avatar.jpg'
import { mapState, mapActions } from 'vuex'

export default {
  name: 'UserAvatar',
  data () {
    return {
      // 头像的图片
      imgURL: img
    }
  },
  computed: {
    ...mapState('user', ['userInfo'])
  },
  async created () {
    this.getUserInfo()
  },
  methods: {
    ...mapActions('user', ['getUserInfo'])
  }
}
</script>

<style lang="less" scoped>
.userAvatar-container {
  padding: 0 0 20px 20px;

  .avatar-box {
    img {
      width: 350px;
      height: 350px;
      object-fit: cover;
    }
  }

  .btns {
    padding-top: 10px;
  }
}
</style>
